package com.zsk.cxf.service.impl;

import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.transport.http.AbstractHTTPDestination;

import com.zsk.cxf.service.IDemoService;
import com.zsk.cxf.service.bean.FileParam;
import com.zsk.cxf.service.bean.UserParam;

@Named
public class DemoServiceImpl implements IDemoService {

    @Override
    public UserParam getUser(String id) {
        UserParam user = new UserParam();
        user.setName("zhangsan");
        user.setAge(28);
        user.setSex(true);
        return user;
    }

    @Override
    public String getUsers(String id, String name) {
        return id + ":" + name;
    }

    @Override
    public UserParam postForm(UserParam user) {
        return user;
    }

    @Override
    public UserParam postUser(String ab, int age, String name, FileParam fileInfo) {
        Message message = PhaseInterceptorChain.getCurrentMessage();
        HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
        System.out.println(request.getHeader("Content-Type"));
        //multipart/form-data获取不到值，需要转化
        System.out.println(request.getParameter("name"));
        
        fileInfo.setAb(ab);
        UserParam user = new UserParam();
        user.setName(name + ":" + ab);
        user.setAge(age);
        user.setSex(true);
        user.setFileInfo(fileInfo);
        return user;
    }

}
